package com.bbva.kyfb.kyfbjpatlsb.dominiotlsb;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class Ttlsbgec.
 */
@Configurable
@Entity
@Table(name = "TTLSBGEC",schema = "TLSB")
@RooJavaBean
@RooToString
@RooEntity(identifierType = TtlsbgecPK.class, versionField = "", persistenceUnit="persistenceUnitTLSB",table = "TTLSBGEC", schema = "TLSB")
@PersistenceContext(unitName="persistenceUnitTLSB")
@RooDbManaged(automaticallyDelete = true)
public class Ttlsbgec {

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AudFmodific: ").append(getAudFmodific()).append(", ");
        sb.append("AudUsuario: ").append(getAudUsuario()).append(", ");
        sb.append("DesRegiswb: ").append(getDesRegiswb()).append(", ");
        sb.append("Id: ").append(getId());
        return sb.toString();
    }

	/** The des regiswb. */
	@Column(name = "DES_REGISWB", columnDefinition = "VARCHAR", length = 500)
    @NotNull
    private String desRegiswb;

	/** The aud fmodific. */
	@Column(name = "AUD_FMODIFIC", columnDefinition = "DATE")
    @NotNull
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date audFmodific;

	/** The aud usuario. */
	@Column(name = "AUD_USUARIO", columnDefinition = "CHAR", length = 8)
    @NotNull
    private String audUsuario;

	/**
	 * Gets the des regiswb.
	 *
	 * @return the des regiswb
	 */
	public String getDesRegiswb() {
        return this.desRegiswb;
    }

	/**
	 * Sets the des regiswb.
	 *
	 * @param desRegiswb the new des regiswb
	 */
	public void setDesRegiswb(String desRegiswb) {
        this.desRegiswb = desRegiswb;
    }

	/**
	 * Gets the aud fmodific.
	 *
	 * @return the aud fmodific
	 */
	public Date getAudFmodific() {
        return this.audFmodific;
    }

	/**
	 * Sets the aud fmodific.
	 *
	 * @param audFmodific the new aud fmodific
	 */
	public void setAudFmodific(Date audFmodific) {
        this.audFmodific = audFmodific;
    }

	/**
	 * Gets the aud usuario.
	 *
	 * @return the aud usuario
	 */
	public String getAudUsuario() {
        return this.audUsuario;
    }

	/**
	 * Sets the aud usuario.
	 *
	 * @param audUsuario the new aud usuario
	 */
	public void setAudUsuario(String audUsuario) {
        this.audUsuario = audUsuario;
    }

	/** The entity manager. */
	@PersistenceContext
    transient EntityManager entityManager;

	/** The id. */
	@EmbeddedId
    private TtlsbgecPK id;

	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public TtlsbgecPK getId() {
        return this.id;
    }

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(TtlsbgecPK id) {
        this.id = id;
    }

	/**
	 * Persist.
	 */
	@Transactional(value="tlsb")
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	/**
	 * Removes the.
	 */
	@Transactional(value="tlsb")
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Ttlsbgec attached = Ttlsbgec.findTtlsbgec(this.id);
            this.entityManager.remove(attached);
        }
    }

	/**
	 * Flush.
	 */
	@Transactional(value="tlsb")
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	/**
	 * Clear.
	 */
	@Transactional(value="tlsb")
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	/**
	 * Merge.
	 *
	 * @return the ttlsbgec
	 */
	@Transactional(value="tlsb")
    public Ttlsbgec merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Ttlsbgec merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	/**
	 * Entity manager.
	 *
	 * @return the entity manager
	 */
	public static final EntityManager entityManager() {
        EntityManager em = new Ttlsbgec().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	
	/**
	 * Count ttlsbgecs.
	 *
	 * @return the long
	 */
	@Transactional(value="tlsb")
	public static long countTtlsbgecs() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Ttlsbgec o", Long.class).getSingleResult();
    }

	
	/**
	 * Find all ttlsbgecs.
	 *
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Ttlsbgec> findAllTtlsbgecs() {
        return entityManager().createQuery("SELECT o FROM Ttlsbgec o", Ttlsbgec.class).getResultList();
    }

	
	/**
	 * Find ttlsbgec.
	 *
	 * @param id the id
	 * @return the ttlsbgec
	 */
	@Transactional(value="tlsb")
	public static Ttlsbgec findTtlsbgec(TtlsbgecPK id) {
        if (id == null) return null;
        return entityManager().find(Ttlsbgec.class, id);
    }

	
	/**
	 * Find ttlsbgec entries.
	 *
	 * @param firstResult the first result
	 * @param maxResults the max results
	 * @return the list
	 */
	@Transactional(value="tlsb")
	public static List<Ttlsbgec> findTtlsbgecEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Ttlsbgec o", Ttlsbgec.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
}
